{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 采集公众号（requests）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "公众号 = \"中大南方青年志愿者服务指导中心\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "fn = { \"output\" : { \"公众号_htm_snippets\": \"data_raw_src/公众号_htm_snippets_{公众号}.tsv\",\n",
    "                    \"公众号_df\": \"data_raw_src/公众号_df_{公众号}.tsv\",\n",
    "                    \"公众号_xlsx\": \"data_raw_src/公众号_url_{公众号}.xlsx\" } \\\n",
    "      }\n",
    "           #pip inastall-upgrade pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 采集公众号（selenium）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from lxml.html import fromstring\n",
    "import time\n",
    "from random import random"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用Selenium\n",
    "- 要更改 opts.binary_location 至自己本地的Chrome浏览器，建议portable\n",
    "- Chrome浏览器 和 chromedriver.exe要同版本号到小数后一位\n",
    "- 要确保可以 开启浏览器机器人\n",
    "- 要确保浏览器机器人 可以打开网页 driver.get(\"https://mp.weixin.qq.com\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# coding=utf-8\n",
    "from selenium import webdriver\n",
    "import time\n",
    "\n",
    "wd = webdriver.Chrome()\n",
    "wd.get(\"https://www.baidu.com\")    # 打开百度浏览器\n",
    "wd.find_element_by_id(\"kw\").send_keys(\"selenium\")   # 定位输入框并输入关键字\n",
    "wd.find_element_by_id(\"su\").click()   #点击[百度一下]搜索\n",
    "time.sleep(3)   #等待3秒\n",
    "wd.quit()   #关闭浏览器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-25-783dcc5c7ea8>:19: DeprecationWarning: use options instead of chrome_options\n",
      "  driver = webdriver.Chrome( chrome_options = opts) #desired_capabilities=caps,\n"
     ]
    }
   ],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.desired_capabilities import DesiredCapabilities\n",
    "\n",
    "\n",
    "#caps=dict()\n",
    "#caps[\"pageLoadStrategy\"] = \"none\"   # Do not wait for full page load\n",
    "\n",
    "opts = webdriver.ChromeOptions()\n",
    "opts.add_argument('--no-sandbox')#解决DevToolsActivePort文件不存在的报错\n",
    "opts.add_argument('window-size=1920x3000') #指定浏览器分辨率\n",
    "opts.add_argument('--disable-gpu') #谷歌文档提到需要加上一这个属性来规避bug\n",
    "opts.add_argument('--hide-scrollbars') #隐藏滚动条, 应对些特殊页面\n",
    "#opts.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度\n",
    "#opts.add_argument('--headless') #浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败\n",
    "# opts.binary_location = \"C:\\portable\\PortableApps\\IronPortable\\App\\Iron\\chrome.exe\"\n",
    "# opts.binary_location = \"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe\" #\"H:\\_coding_\\Gitee\\InternetNewMedia\\CapstonePrj2016\\chromedriver.exe\"  \n",
    "\n",
    "# \"H:\\_coding_\\Gitee\\InternetNewMedia\\CapstonePrj2016\\chromedriver.exe\"  \n",
    "driver = webdriver.Chrome( chrome_options = opts) #desired_capabilities=caps,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.get(\"https://mp.weixin.qq.com\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 填表登入\n",
    "selenium 的定位方法\n",
    "\n",
    "- find_element_by_id     根据标签id定位\n",
    "- find_element_by_name     根据标签的name定位\n",
    "- find_element_by_xpath     根据xpath定位\n",
    "- find_element_by_link_text     通过文字链接来定位元素\n",
    "- find_element_by_partial_link_text     通过文字链接来定位元素\n",
    "- find_element_by_tag_name     根据标签的名字定位\n",
    "- find_element_by_class_name     通过class name 定位\n",
    "- find_element_by_css_selector     根据元素属性来定位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "payload =  {\"account\": \"1572390501@qq.com\", \"password\": \"20011121wsq\"}\n",
    "# 切换为账号密码登录\n",
    "element = driver.find_element_by_xpath('//div[@class=\"login__type__container login__type__container__scan\"]/a')\n",
    "element.get_attribute('innerHTML')\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"account\"]').clear()\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"account\"]').send_keys(payload['account'])\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"password\"]').clear()\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"password\"]').send_keys(payload['password'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "#点击登录\n",
    "driver.find_element_by_xpath('//div[@class=\"login_btn_panel\"]/a').click()\n",
    "#然后手机扫码"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 新建图文消息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//div[@class=\"new-creation__menu-item\"]//div[@class=\"new-creation__menu-content\"]').click()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 超链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.switch_to.window(driver.window_handles[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "element = driver.find_element_by_xpath('//*[@id=\"js_editor_insertlink\"]').click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 选择其他公众号\n",
    "driver.find_element_by_xpath('//button[@class=\"weui-desktop-btn weui-desktop-btn_default\"]').click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 输入公众号名称\n",
    "driver.find_element_by_xpath('//form//div[@class=\"inner_link_account_area\"]//input[@class=\"weui-desktop-form__input\"]').clear()\n",
    "driver.find_element_by_xpath('//form//div[@class=\"inner_link_account_area\"]//input[@class=\"weui-desktop-form__input\"]').send_keys(\"中大南方青年志愿者服务指导中心\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "from selenium.webdriver.common.action_chains import ActionChains"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 搜索\n",
    "driver.find_element_by_xpath('//button[@class=\"weui-desktop-icon-btn weui-desktop-search__btn\"]').click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/PFrnv2qeEdo7WKQeFtkibvRvW1LWp3I2lHadfa464ASCQf0dZBtKPvibGNdmIfZNMjvrwJcoa3OIIOPb5o5Jzdww/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">中大南方青年志愿者服务指导中心</strong> <i class=\"inner_link_account_wechat\">微信号：qnzyzfwzdzx</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/wm6QZA6ZDgicReHP4fOobwpMTr2I0mfYLLwXuj8cckibsCQr1KiaibakuNLvIKtCNrg1DHxibduJBOsCgFS1oboY07Q/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">广东志愿者</strong> <i class=\"inner_link_account_wechat\">微信号：gd_zyz</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/GOCxZumiaMW2jZwv0SOtZI87f7xYdoa9VnZfbnGTpYEGFoficu8DwicJ7DiauWFOXqUtaia7xia1JDXxfymiahNU1ickHg/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">南方医科大学青年志愿者协会</strong> <i class=\"inner_link_account_wechat\">微信号：nanyiqingxie</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/cWTno3KzcxKdeiahCqbicrysjWdZ7eo2H3icRLPayBcDqWpqaZHYdIAvVuoaEq6RPeyaJBHic90eS49HvnQGB9BOsQ/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">中冶南方青年</strong> <i class=\"inner_link_account_wechat\">微信号：未设置</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/F0gaMhibB8l1xaQsqzMic8hL5WEf4GfsPvkZ0lx3STf8cva41UrgWehX3Fhwuz1h911GDUN8mQIxKibVDAJ1Jbf7A/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">南航青年志愿者协会</strong> <i class=\"inner_link_account_wechat\">微信号：CS_YVA</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li>\n"
     ]
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//ul[@class=\"inner_link_account_list\"]')\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "公众号SERP = main_content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 解析\n",
    "root = fromstring(公众号SERP) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "主 = root.xpath('//li[@class=\"inner_link_account_item\"]')\n",
    "\n",
    "account_list = []\n",
    "for e in 主:\n",
    "    account_nickname = e.xpath('./div/strong[@class=\"inner_link_account_nickname\"]')[0].text\n",
    "    account_wechat = e.xpath('./div/i[@class=\"inner_link_account_wechat\"]')[0].text\n",
    "    account_img = e.xpath('./div/img/@src')[0]\n",
    "    account = {\"nickname\": account_nickname, \"wechat\": account_wechat, \"img\": account_img,}\n",
    "    account_list.append(account)\n",
    "\n",
    "df_account = pd.DataFrame(account_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>nickname</th>\n",
       "      <th>wechat</th>\n",
       "      <th>img</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>中大南方青年志愿者服务指导中心</td>\n",
       "      <td>微信号：qnzyzfwzdzx</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/PFrnv2qeEdo7WKQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>广东志愿者</td>\n",
       "      <td>微信号：gd_zyz</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/wm6QZA6ZDgicReH...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>南方医科大学青年志愿者协会</td>\n",
       "      <td>微信号：nanyiqingxie</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/GOCxZumiaMW2jZw...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>中冶南方青年</td>\n",
       "      <td>微信号：未设置</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/cWTno3KzcxKdeia...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>南航青年志愿者协会</td>\n",
       "      <td>微信号：CS_YVA</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/F0gaMhibB8l1xaQ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          nickname            wechat  \\\n",
       "0  中大南方青年志愿者服务指导中心   微信号：qnzyzfwzdzx   \n",
       "1            广东志愿者        微信号：gd_zyz   \n",
       "2    南方医科大学青年志愿者协会  微信号：nanyiqingxie   \n",
       "3           中冶南方青年           微信号：未设置   \n",
       "4        南航青年志愿者协会        微信号：CS_YVA   \n",
       "\n",
       "                                                 img  \n",
       "0  http://mmbiz.qpic.cn/mmbiz_png/PFrnv2qeEdo7WKQ...  \n",
       "1  http://mmbiz.qpic.cn/mmbiz_png/wm6QZA6ZDgicReH...  \n",
       "2  http://mmbiz.qpic.cn/mmbiz_png/GOCxZumiaMW2jZw...  \n",
       "3  http://mmbiz.qpic.cn/mmbiz_png/cWTno3KzcxKdeia...  \n",
       "4  http://mmbiz.qpic.cn/mmbiz_png/F0gaMhibB8l1xaQ...  "
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//ul[@class=\"inner_link_account_list\"]/li').click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n跳转_input = driver.find_element_by_xpath(\\'//span[@class=\"weui-desktop-pagination__form\"]/input\\')\\n跳转_a = driver.find_element_by_xpath(\\'//span[@class=\"weui-desktop-pagination__form\"]/a\\')\\n跳转_input.clear()\\n跳转_input.send_keys(2)\\n跳转_a.click()\\n'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 跳转testing\n",
    "'''\n",
    "跳转_input = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/input')\n",
    "跳转_a = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/a')\n",
    "跳转_input.clear()\n",
    "跳转_input.send_keys(2)\n",
    "跳转_a.click()\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 86]\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 跳转上限\n",
    "l_e = driver.find_elements_by_xpath('//label[@class=\"weui-desktop-pagination__num\"]')\n",
    "l_e_int  = [int(x.text) for x in l_e] \n",
    "print (l_e_int)\n",
    "print (l_e_int[0]==l_e_int[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86]\n"
     ]
    }
   ],
   "source": [
    "pages = list(range(l_e_int[0],l_e_int[-1]+1 ))\n",
    "#print(pages[0:2])\n",
    "pages = list(range(1,l_e_int[-1]+1 ))\n",
    "print(pages)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 循环/遍历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "# global varialbes \n",
    "html_raw = dict()\n",
    "main_content =\"\"\n",
    "element = None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "def process_pages (pages):\n",
    "    for p in pages:\n",
    "        print (p,end='\\t')\n",
    "\n",
    "        跳转_input = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/input')\n",
    "        跳转_a = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/a')\n",
    "        跳转_input.clear()\n",
    "        跳转_input.send_keys(p)\n",
    "        跳转_a.click()\n",
    "\n",
    "        time.sleep(1+12*random())\n",
    "\n",
    "        element = driver.find_element_by_xpath('//div[@class=\"inner_link_article_list\"]')\n",
    "        main_content = element.get_attribute('innerHTML')\n",
    "#         print(main_content)\n",
    "        html_raw[p] = main_content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\t25\t26\t27\t28\t29\t30\t31\t32\t33\t34\t35\t36\t37\t38\t39\t40\t41\t42\t43\t44\t45\t46\t47\t48\t49\t50\t51\t52\t53\t54\t55\t56\t57\t58\t59\t60\t61\t62\t63\t64\t65\t66\t67\t68\t69\t70\t71\t72\t73\t74\t75\t76\t77\t78\t79\t80\t81\t82\t83\t84\t85\t86\t"
     ]
    }
   ],
   "source": [
    "process_pages(pages)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>html_snippets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>86 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        html_snippets\n",
       "1   <div class=\"weui-desktop-radio-group\"><label c...\n",
       "2   <div class=\"weui-desktop-radio-group\"><label c...\n",
       "3   <div class=\"weui-desktop-radio-group\"><label c...\n",
       "4   <div class=\"weui-desktop-radio-group\"><label c...\n",
       "5   <div class=\"weui-desktop-radio-group\"><label c...\n",
       "..                                                ...\n",
       "82  <div class=\"weui-desktop-radio-group\"><label c...\n",
       "83  <div class=\"weui-desktop-radio-group\"><label c...\n",
       "84  <div class=\"weui-desktop-radio-group\"><label c...\n",
       "85  <div class=\"weui-desktop-radio-group\"><label c...\n",
       "86  <div class=\"weui-desktop-radio-group\"><label c...\n",
       "\n",
       "[86 rows x 1 columns]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame([html_raw]).T\n",
    "df.columns = [\"html_snippets\"]\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stored 'html_raw' (dict)\n"
     ]
    }
   ],
   "source": [
    "%store html_raw\n",
    "import pickle \n",
    "filehandler = open(\"html_raw\", 'wb') \n",
    "pickle.dump(html_raw, filehandler)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "81\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>html_snippets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>&lt;div class=\"weui-desktop-radio-group\"&gt;&lt;label c...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        html_snippets\n",
       "12  <div class=\"weui-desktop-radio-group\"><label c...\n",
       "83  <div class=\"weui-desktop-radio-group\"><label c...\n",
       "84  <div class=\"weui-desktop-radio-group\"><label c...\n",
       "85  <div class=\"weui-desktop-radio-group\"><label c...\n",
       "86  <div class=\"weui-desktop-radio-group\"><label c..."
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_out = df[~df.duplicated()]\n",
    "print (len(df_out))\n",
    "df[df.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[12, 83, 84, 85, 86]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[12, 83, 84, 85, 86]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "try_again = list(df[df.duplicated()].index)\n",
    "print(try_again)\n",
    "try_again = try_again + list (set(pages).difference(set(df.index.values)))\n",
    "try_again"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 暂存档"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename = fn [\"output\"] [\"公众号_htm_snippets\"] \n",
    "df_out.to_csv(filename.format(公众号=公众号), sep=\"\\t\", encoding=\"utf8\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5,5,8,5,9,8,7,6,7,5,15,5,7,5,5,6,6,7,5,5,10,5,8,8,7,6,5,5,5,5,15,8,5,5,6,5,7,5,5,5,6,7,7,6,9,9,7,5,6,5,13,6,5,6,7,5,8,6,9,7,8,6,5,5,5,6,6,9,6,5,19,12,11,7,8,7,7,8,6,7,6,6,6,6,6,6,"
     ]
    }
   ],
   "source": [
    "def parse_html_snippets(_snippet_):\n",
    "    root = fromstring(_snippet_) \n",
    "    title = [x for x in root.xpath('//span/text()')]\n",
    "    create_time = [x.text for x in root.xpath('//div[@class=\"inner_link_article_date\"]')]\n",
    "    link = [x for x in root.xpath('//a/@href')]\n",
    "    _df_ = pd.DataFrame({\"title\":title, \"create_time\": create_time, \"link\":link})\n",
    "    return(_df_)\n",
    "    \n",
    "l_df = []\n",
    "for p in pages:\n",
    "    _df_ = parse_html_snippets(df.loc[p,\"html_snippets\"])\n",
    "    print (len(_df_), end=\",\")\n",
    "    l_df.append(_df_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>齐心抗疫，感恩有你丨广州南方学院全校核酸检测工作顺利完成</td>\n",
       "      <td>2021-06-06</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>分享图片</td>\n",
       "      <td>2021-06-05</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>公示丨关于第一届广州南方学院“最美志愿者”提名候选人名单的公示</td>\n",
       "      <td>2021-06-02</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>应急知识存于心，安全志愿实于行｜2021年广州南方学院志愿活动应急培训会顺利举行</td>\n",
       "      <td>2021-05-28</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>通知丨关于广州南方学院志愿活动应急培训会通知</td>\n",
       "      <td>2021-05-25</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>584</th>\n",
       "      <td>无偿献血活动 | 明天你会不会来？</td>\n",
       "      <td>2016-10-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>585</th>\n",
       "      <td>无偿献血活动 | 捐献热血，不见不散。</td>\n",
       "      <td>2016-10-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>586</th>\n",
       "      <td>无偿献血活动 | 为了你，我愿意。</td>\n",
       "      <td>2016-10-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>587</th>\n",
       "      <td>LOOKBOOK | 2016全新系列服饰 青志文化缩影型录</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>588</th>\n",
       "      <td>Schedule | 青志一周活动安排</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>589 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        title create_time  \\\n",
       "0                齐心抗疫，感恩有你丨广州南方学院全校核酸检测工作顺利完成  2021-06-06   \n",
       "1                                        分享图片  2021-06-05   \n",
       "2             公示丨关于第一届广州南方学院“最美志愿者”提名候选人名单的公示  2021-06-02   \n",
       "3    应急知识存于心，安全志愿实于行｜2021年广州南方学院志愿活动应急培训会顺利举行  2021-05-28   \n",
       "4                      通知丨关于广州南方学院志愿活动应急培训会通知  2021-05-25   \n",
       "..                                        ...         ...   \n",
       "584                         无偿献血活动 | 明天你会不会来？  2016-10-20   \n",
       "585                       无偿献血活动 | 捐献热血，不见不散。  2016-10-19   \n",
       "586                         无偿献血活动 | 为了你，我愿意。  2016-10-18   \n",
       "587            LOOKBOOK | 2016全新系列服饰 青志文化缩影型录  2016-10-17   \n",
       "588                       Schedule | 青志一周活动安排  2016-10-17   \n",
       "\n",
       "                                                  link  \n",
       "0    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "1    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "2    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "3    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "4    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "..                                                 ...  \n",
       "584  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "585  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "586  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "587  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "588  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "\n",
       "[589 rows x 3 columns]"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out = pd.concat(l_df).reset_index(drop=True)\n",
    "df_url_out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>迎新志愿活动总结丨志在远方，愿在校园</td>\n",
       "      <td>2020-09-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>公示丨2020年度春季中山大学南方学院返校优秀志愿者名单公示</td>\n",
       "      <td>2020-09-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>通知丨2020年秋季学期学生返校工作第四批次志愿者招募</td>\n",
       "      <td>2020-09-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>通知丨2020年秋季学期学生返校工作第三批次志愿者招募</td>\n",
       "      <td>2020-09-06</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>关于协助开展2020年广东大学生志愿服务山区计划（希望乡村教师计划专项）第二轮招募动员的工作指引</td>\n",
       "      <td>2020-09-03</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>565</th>\n",
       "      <td>红十字会动态 | 无偿献血活动圆满结束</td>\n",
       "      <td>2016-10-22</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>566</th>\n",
       "      <td>无偿献血活动 | 明天你会不会来？</td>\n",
       "      <td>2016-10-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>567</th>\n",
       "      <td>无偿献血活动 | 捐献热血，不见不散。</td>\n",
       "      <td>2016-10-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>568</th>\n",
       "      <td>无偿献血活动 | 为了你，我愿意。</td>\n",
       "      <td>2016-10-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>569</th>\n",
       "      <td>LOOKBOOK | 2016全新系列服饰 青志文化缩影型录</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>570</th>\n",
       "      <td>Schedule | 青志一周活动安排</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571</th>\n",
       "      <td>红十字会动态 | 无偿献血活动圆满结束</td>\n",
       "      <td>2016-10-22</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>572</th>\n",
       "      <td>无偿献血活动 | 明天你会不会来？</td>\n",
       "      <td>2016-10-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>573</th>\n",
       "      <td>无偿献血活动 | 捐献热血，不见不散。</td>\n",
       "      <td>2016-10-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>574</th>\n",
       "      <td>无偿献血活动 | 为了你，我愿意。</td>\n",
       "      <td>2016-10-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>575</th>\n",
       "      <td>LOOKBOOK | 2016全新系列服饰 青志文化缩影型录</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>576</th>\n",
       "      <td>Schedule | 青志一周活动安排</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>577</th>\n",
       "      <td>红十字会动态 | 无偿献血活动圆满结束</td>\n",
       "      <td>2016-10-22</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>无偿献血活动 | 明天你会不会来？</td>\n",
       "      <td>2016-10-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>579</th>\n",
       "      <td>无偿献血活动 | 捐献热血，不见不散。</td>\n",
       "      <td>2016-10-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580</th>\n",
       "      <td>无偿献血活动 | 为了你，我愿意。</td>\n",
       "      <td>2016-10-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>581</th>\n",
       "      <td>LOOKBOOK | 2016全新系列服饰 青志文化缩影型录</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>582</th>\n",
       "      <td>Schedule | 青志一周活动安排</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>583</th>\n",
       "      <td>红十字会动态 | 无偿献血活动圆满结束</td>\n",
       "      <td>2016-10-22</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>584</th>\n",
       "      <td>无偿献血活动 | 明天你会不会来？</td>\n",
       "      <td>2016-10-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>585</th>\n",
       "      <td>无偿献血活动 | 捐献热血，不见不散。</td>\n",
       "      <td>2016-10-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>586</th>\n",
       "      <td>无偿献血活动 | 为了你，我愿意。</td>\n",
       "      <td>2016-10-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>587</th>\n",
       "      <td>LOOKBOOK | 2016全新系列服饰 青志文化缩影型录</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>588</th>\n",
       "      <td>Schedule | 青志一周活动安排</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                title create_time  \\\n",
       "80                                 迎新志愿活动总结丨志在远方，愿在校园  2020-09-21   \n",
       "81                     公示丨2020年度春季中山大学南方学院返校优秀志愿者名单公示  2020-09-17   \n",
       "82                        通知丨2020年秋季学期学生返校工作第四批次志愿者招募  2020-09-10   \n",
       "83                        通知丨2020年秋季学期学生返校工作第三批次志愿者招募  2020-09-06   \n",
       "84   关于协助开展2020年广东大学生志愿服务山区计划（希望乡村教师计划专项）第二轮招募动员的工作指引  2020-09-03   \n",
       "565                               红十字会动态 | 无偿献血活动圆满结束  2016-10-22   \n",
       "566                                 无偿献血活动 | 明天你会不会来？  2016-10-20   \n",
       "567                               无偿献血活动 | 捐献热血，不见不散。  2016-10-19   \n",
       "568                                 无偿献血活动 | 为了你，我愿意。  2016-10-18   \n",
       "569                    LOOKBOOK | 2016全新系列服饰 青志文化缩影型录  2016-10-17   \n",
       "570                               Schedule | 青志一周活动安排  2016-10-17   \n",
       "571                               红十字会动态 | 无偿献血活动圆满结束  2016-10-22   \n",
       "572                                 无偿献血活动 | 明天你会不会来？  2016-10-20   \n",
       "573                               无偿献血活动 | 捐献热血，不见不散。  2016-10-19   \n",
       "574                                 无偿献血活动 | 为了你，我愿意。  2016-10-18   \n",
       "575                    LOOKBOOK | 2016全新系列服饰 青志文化缩影型录  2016-10-17   \n",
       "576                               Schedule | 青志一周活动安排  2016-10-17   \n",
       "577                               红十字会动态 | 无偿献血活动圆满结束  2016-10-22   \n",
       "578                                 无偿献血活动 | 明天你会不会来？  2016-10-20   \n",
       "579                               无偿献血活动 | 捐献热血，不见不散。  2016-10-19   \n",
       "580                                 无偿献血活动 | 为了你，我愿意。  2016-10-18   \n",
       "581                    LOOKBOOK | 2016全新系列服饰 青志文化缩影型录  2016-10-17   \n",
       "582                               Schedule | 青志一周活动安排  2016-10-17   \n",
       "583                               红十字会动态 | 无偿献血活动圆满结束  2016-10-22   \n",
       "584                                 无偿献血活动 | 明天你会不会来？  2016-10-20   \n",
       "585                               无偿献血活动 | 捐献热血，不见不散。  2016-10-19   \n",
       "586                                 无偿献血活动 | 为了你，我愿意。  2016-10-18   \n",
       "587                    LOOKBOOK | 2016全新系列服饰 青志文化缩影型录  2016-10-17   \n",
       "588                               Schedule | 青志一周活动安排  2016-10-17   \n",
       "\n",
       "                                                  link  \n",
       "80   http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "81   http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "82   http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "83   http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "84   http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "565  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "566  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "567  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "568  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "569  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "570  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "571  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "572  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "573  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "574  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "575  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "576  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "577  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "578  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "579  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "580  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "581  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "582  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "583  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "584  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "585  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "586  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "587  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "588  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  "
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out[df_url_out.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>value</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>分享图片</td>\n",
       "      <td>2021-06-05</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>转载丨明晚(周一)19:30！锁定西部(山区)计划直播间！</td>\n",
       "      <td>2021-04-25</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>分享图片</td>\n",
       "      <td>2021-04-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>转载丨直播丨4月15日云访校宣讲会，不见不散。</td>\n",
       "      <td>2021-04-06</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>分享图片</td>\n",
       "      <td>2021-04-04</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580</th>\n",
       "      <td>无偿献血活动 | 为了你，我愿意。</td>\n",
       "      <td>2016-10-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>583</th>\n",
       "      <td>红十字会动态 | 无偿献血活动圆满结束</td>\n",
       "      <td>2016-10-22</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>584</th>\n",
       "      <td>无偿献血活动 | 明天你会不会来？</td>\n",
       "      <td>2016-10-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>585</th>\n",
       "      <td>无偿献血活动 | 捐献热血，不见不散。</td>\n",
       "      <td>2016-10-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>586</th>\n",
       "      <td>无偿献血活动 | 为了你，我愿意。</td>\n",
       "      <td>2016-10-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>222 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                               title create_time  \\\n",
       "value                                              \n",
       "1                               分享图片  2021-06-05   \n",
       "10     转载丨明晚(周一)19:30！锁定西部(山区)计划直播间！  2021-04-25   \n",
       "13                              分享图片  2021-04-20   \n",
       "17           转载丨直播丨4月15日云访校宣讲会，不见不散。  2021-04-06   \n",
       "18                              分享图片  2021-04-04   \n",
       "...                              ...         ...   \n",
       "580                无偿献血活动 | 为了你，我愿意。  2016-10-18   \n",
       "583              红十字会动态 | 无偿献血活动圆满结束  2016-10-22   \n",
       "584                无偿献血活动 | 明天你会不会来？  2016-10-20   \n",
       "585              无偿献血活动 | 捐献热血，不见不散。  2016-10-19   \n",
       "586                无偿献血活动 | 为了你，我愿意。  2016-10-18   \n",
       "\n",
       "                                                    link  \n",
       "value                                                     \n",
       "1      http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "10     http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "13     http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "17     http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "18     http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "...                                                  ...  \n",
       "580    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "583    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "584    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "585    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "586    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "\n",
       "[222 rows x 3 columns]"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# tagging 标记\n",
    "tagging_list = [\"\",\"志愿\",\"南方\",\"青志\",\"优秀\",\"大会\"] #overwritable\n",
    "\n",
    "v_v_list = []\n",
    "\n",
    "for tag in tagging_list:\n",
    "    index_list = df_url_out [ df_url_out.title.str.contains(tag) ].index.to_list()\n",
    "    v_v_pairs = pd.DataFrame({tag:index_list}).melt().set_index(\"value\")\n",
    "    v_v_list.append(v_v_pairs)\n",
    "\n",
    "df_cat = v_v_list[0]\n",
    "for d in v_v_list:\n",
    "    df_cat.update(d)\n",
    "    \n",
    "# 尚未标记内容\n",
    "df_url_out.loc [ df_cat.query('variable==\"\"').index ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'DataFrame' object has no attribute 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-108-066205bbc927>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf_url_out\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mdf_url_out\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcontains\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"志愿\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m   5272\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_can_hold_identifiers_and_holds_name\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   5273\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 5274\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   5275\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   5276\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'str'"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>齐心抗疫，感恩有你丨广州南方学院全校核酸检测工作顺利完成</td>\n",
       "      <td>2021-06-06</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>分享图片</td>\n",
       "      <td>2021-06-05</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>公示丨关于第一届广州南方学院“最美志愿者”提名候选人名单的公示</td>\n",
       "      <td>2021-06-02</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>应急知识存于心，安全志愿实于行｜2021年广州南方学院志愿活动应急培训会顺利举行</td>\n",
       "      <td>2021-05-28</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>通知丨关于广州南方学院志愿活动应急培训会通知</td>\n",
       "      <td>2021-05-25</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>560</th>\n",
       "      <td>无偿献血活动 | 明天你会不会来？</td>\n",
       "      <td>2016-10-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>561</th>\n",
       "      <td>无偿献血活动 | 捐献热血，不见不散。</td>\n",
       "      <td>2016-10-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>562</th>\n",
       "      <td>无偿献血活动 | 为了你，我愿意。</td>\n",
       "      <td>2016-10-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>563</th>\n",
       "      <td>LOOKBOOK | 2016全新系列服饰 青志文化缩影型录</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>564</th>\n",
       "      <td>Schedule | 青志一周活动安排</td>\n",
       "      <td>2016-10-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>560 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        title create_time  \\\n",
       "0                齐心抗疫，感恩有你丨广州南方学院全校核酸检测工作顺利完成  2021-06-06   \n",
       "1                                        分享图片  2021-06-05   \n",
       "2             公示丨关于第一届广州南方学院“最美志愿者”提名候选人名单的公示  2021-06-02   \n",
       "3    应急知识存于心，安全志愿实于行｜2021年广州南方学院志愿活动应急培训会顺利举行  2021-05-28   \n",
       "4                      通知丨关于广州南方学院志愿活动应急培训会通知  2021-05-25   \n",
       "..                                        ...         ...   \n",
       "560                         无偿献血活动 | 明天你会不会来？  2016-10-20   \n",
       "561                       无偿献血活动 | 捐献热血，不见不散。  2016-10-19   \n",
       "562                         无偿献血活动 | 为了你，我愿意。  2016-10-18   \n",
       "563            LOOKBOOK | 2016全新系列服饰 青志文化缩影型录  2016-10-17   \n",
       "564                       Schedule | 青志一周活动安排  2016-10-17   \n",
       "\n",
       "                                                  link  \n",
       "0    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "1    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "2    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "3    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "4    http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "..                                                 ...  \n",
       "560  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "561  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "562  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "563  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "564  http://mp.weixin.qq.com/s?__biz=MzI1ODQxOTQ3NQ...  \n",
       "\n",
       "[560 rows x 3 columns]"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out[~df_url_out.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [],
   "source": [
    "with pd.ExcelWriter('{公众号}公众号_url_.xlsx'.format(公众号=公众号),mode='w',engine=\"openpyxl\") as writer:  \n",
    "            df_url_out.to_excel(writer, sheet_name=公众号)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'df_o' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-93-28f128f87184>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mdf_account\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"rel_accounts\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mdf_o\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"url_cat\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0mdf_stats\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"stats\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'df_o' is not defined"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
